package com.jiandaoshou.fragments;

import android.content.Intent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jiandaoshou.JinRiDingDanAct;
import com.jiandaoshou.R;
import com.jiandaoshou.base.BaseFragment;
import com.jiandaoshou.entry.ShouYeInfo;
import com.jiandaoshou.http.APIDefine;
import com.jiandaoshou.http.Http;
import com.jiandaoshou.utils.DingDanType;
import com.jiandaoshou.utils.JsonUtil;

import java.util.Calendar;
import java.util.HashMap;

public class ShouYeFragment extends BaseFragment implements View.OnClickListener {
    //订单
    private LinearLayout Linear_DingDan;
    //今日订单
    private LinearLayout DingDan_JinRi;
    private TextView     Tv_Count_Today;
    private TextView     Tv_Jine_Today;
    //昨日订单
    private LinearLayout DingDan_ZuoRi;
    private TextView     Tv_Count_Yesterday;
    private TextView     Tv_Jine_Yesterday;
    //前日订单
    private LinearLayout DingDan_QianRi;
    private TextView     Tv_Count_BeforeYesterday;
    private TextView     Tv_Jine_BeforeYesterday;
    //当前月份的TextView
    private TextView     Tv_Current_Month;
    private String  shopID;
    @Override
    protected void lazyLoad() {
     //获取网络请求的参数shopID
        shopID=getArguments().getString("shopId","");
        HashMap<String,String> map=new HashMap<>();
        map.put("strShopID",shopID);
        Http.post(APIDefine.TF_Interface_GetTodayYesterday, map, new Http.HttpCallBack() {
            @Override
            public void onHttpSuccess(String response) {
                ShouYeInfo shouYeInfo= JsonUtil.parser.fromJson(response, ShouYeInfo.class);
                Tv_Count_Today.setText(shouYeInfo.getnTodayCount()+"");
                Tv_Jine_Today.setText(shouYeInfo.getStrTodaySumMoney());
                Tv_Count_Yesterday.setText(shouYeInfo.getnYesterdayCount()+"");
                Tv_Jine_Yesterday.setText(shouYeInfo.getStrYesterSumMoney());
                Tv_Count_BeforeYesterday.setText(shouYeInfo.getnBeforeYesterdayCount()+"");
                Tv_Jine_BeforeYesterday.setText(shouYeInfo.getStrBeforeYesterdaySumMoney());
            }
        });
    }

    @Override
    protected int getContentView() {
        return R.layout.activity_shou_ye;
    }

    @Override
    protected void init() {
        DingDan_JinRi = $(R.id.dingdan_jinri);
        DingDan_ZuoRi = $(R.id.dingdan_zuori);
        DingDan_QianRi = $(R.id.dingdan_qianri);
        Linear_DingDan = $(R.id.lin_dingdan);
        //今日订单
        Tv_Count_Today=$(R.id.count_today);
        Tv_Jine_Today=$(R.id.jine_today);
        //昨日订单
        Tv_Count_Yesterday=$(R.id.count_yesterday);
        Tv_Jine_Yesterday=$(R.id.jine_yesterday);
        //前日订单
        Tv_Count_BeforeYesterday=$(R.id.count_beforeyesterday);
        Tv_Jine_BeforeYesterday=$(R.id.jine_beforeyesterday);
        //显示当前月份的TextView
        Tv_Current_Month=$(R.id.current_month);
        //获取首页的当前月份
        Calendar time=Calendar.getInstance();
        Tv_Current_Month.setText((time.get(Calendar.MONTH)+1)+"月");
        Linear_DingDan.setOnClickListener(this);
        DingDan_JinRi.setOnClickListener(this);
        DingDan_QianRi.setOnClickListener(this);
        DingDan_ZuoRi.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        Intent intent=new Intent(getActivity(), JinRiDingDanAct.class);
        switch(view.getId()){
            //本月订单
            case R.id.lin_dingdan:
                intent.putExtra("type", DingDanType.CURRENTMONTH);
                break;
            //今日订单
            case R.id.dingdan_jinri:
                intent.putExtra("type", DingDanType.TODAY);
                break;
            // 昨日订单
            case R.id.dingdan_zuori:
                intent.putExtra("type", DingDanType.YESTERDAY);
                break;
            //前日订单
            case R.id.dingdan_qianri:
                intent.putExtra("type", DingDanType.BEFOREYESTORDAY);
                break;
        }
        intent.putExtra("shopID",shopID);
        startActivity(intent);
    }
}
